import http from "@src/config/http.ts"
import backendUrlSet from "@src/config/backendUrlSet.ts";

const baseURL = "http://" + backendUrlSet

//https://binaryify.github.io/NeteaseCloudMusicApi/#/
interface ApiType {
    [key: string]: string;
}

// api接口 - 此处用了统一保存接口url路径
const api: ApiType = {
    getChatroomList: '/api/chatroom-list', //获取所有聊天室列表
};
for (const key in api) {
    api[key] = `${baseURL}${api[key]}`;
}

export interface CurrentSong {
    id: number;
    name: string;
    time: number;
    author: string;
    picUrl: string;
}

export interface RoomType {
    roomID: number;
    img: string;
    title: string;
    intro: string;
    maxUsersLength: number;
    isPlaying: boolean;
    currentSong: CurrentSong;
}

export interface template<T> {
    code: number;
    data: T;
    message: string;
}

//获取聊天室列表
export const getChatroomList = () => {
    return http.get<template<RoomType[]>>(api.getChatroomList)
}

//获取聊天室歌曲列表
export const getChatroomSongs = (roomId: number) => {
    return http.get<template<CurrentSong[]>>(`${baseURL}/api/chatroom/${roomId}/songs`)
}
//添加歌曲到聊天室
export const addChatroomSong = (roomId: number, currentSong: CurrentSong) => {
    return http.post<template<string>>(`${baseURL}/api/chatroom/${roomId}/songs`, currentSong)
}

